# def login():
# 	#获取lt
# 	url_home='https://hrx-sit.ctg.cn/corehr/#/home'
# 	url_lt='http://testiam.ctg.cn:9020/asd/sso/login?service=http://testiam.ctg.cn:9020/asd/sso/oauth2.0/callbackAuthorize'
# 	# url_casService='http://testiam.ctg.cn:9020/asd/sso/login?service=http%3A%2F%2Ftestiam.ctg.cn%3A9020%2Fasd%2Fsso%2Foauth2.0%2FcallbackAuthorize'
# 	url_casService='http://testiam.ctg.cn:9020/asd/sso/oauth2.0/callbackAuthorize'

# 	r=requests.get(url=url_lt)
# 	print(r.headers['Set-Cookie'])
# 	lt=re.findall('name="lt" value="(.+?)"',r.text)
# 	print(lt[0])
# 	headers={
# 		"Cookie":r.headers['Set-Cookie'],
# 		"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36"
# 	}
# 	data={
# 		"username": "ihr25",
# 		"password": "",
# 		"authMode": "jdbc",
# 		"lt": lt[0],
# 		"execution": "e2s1",
# 		"_eventId": "submit",
# 	}
# 	r=requests.post(url=url_lt, headers=headers, data=data)
# 	print(r.status_code)
# 	return r

import requests
import urllib3
import re
# from lxml import etree
# from ows_scrapy.ows_spider.write_csv import write_list_to_csv

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)


s = requests.session()
# s.trust_env = False     # fastercookie = Noneusername = 'username'password = 'pwd'def login():
headers = {        
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
	'Accept-Encoding': 'gzip, deflate',
	'Accept-Language': 'zh-CN,zh;q=0.9',
	'Connection': 'keep-alive',
	'Cookie': 'JSESSIONID=1259BAA6C9351BF6EAE7038B8B27F852',
	'Host': 'testiam.ctg.cn:9020',
	'Upgrade-Insecure-Requests': '1',
	'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36'
    }

# # login_url = 'https://hrx-sit.ctg.cn/corehr/#/home'
login_url = 'http://testiam.ctg.cn:9020/asd/sso/login?service=http%3A%2F%2Ftestiam.ctg.cn%3A9020%2Fasd%2Fsso%2Foauth2.0%2FcallbackAuthorize'
res = s.get(url=login_url, headers=headers, verify=False)    
print(s.headers)
print(res.headers)
# global cookie
# cookie = res.cookies# 注意要保存cookie
# # print(dir(cookie))
# print(cookie)
# # print("get response from ows {0}, http status {1}".format(login_url, res.status_code))

# login_url = res.url

# headers['Referer'] = 'http://testiam.ctg.cn:9020/asd/sso/login?service=http%3A%2F%2Ftestiam.ctg.cn%3A9020%2Fasd%2Fsso%2Foauth2.0%2FcallbackAuthorize'
# headers['Origin'] = 'http://testiam.ctg.cn:9020'
# headers['Content-Type'] = 'application/x-www-form-urlencoded'
# headers['Cache-Control'] = 'max-age=0'
# # headers['cookie'] = cookie
# lt=re.findall('name="lt" value="(.+?)"',res.text)
# # print(headers)
# data = {
# 		"username": "ihr25",
# 		"password": "8327fb24f51b8506e242fb016216a7cf06c1d747c5fb975e972eb267af432689b183ac3d9f269c7a01b99c327b23578c5723043eeb6dfff240ebff83b9ae63ca9d64ffd718f4f0f9fb3d9614f6f794592fe035b9c9eed0dab67395a7ac3edf6a462bfc7dc622cda0ecc9487f331f03e10160cad717da1898e8e76760a9d731e7",
# 		"authMode": "jdbc",
# 		"execution": "e3s1",
# 		"_eventId": "submit",
# 		'lt': lt[0]
# 	}
# # print(form_data)
# res = s.post(url=login_url, headers=headers, data=data, allow_redirects=False, verify=False)
# print(res.headers,res.status_code)